﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Audio {

	/// <summary>
	/// Vortex2D.NET sound device class
	/// </summary>
	public sealed class SoundDevice {
		///<summary>Instance of sound Vortex2D.NET sound device</summary>
		static public SoundDevice Instance { get; private set; }
		///<summary>Internal reference to irrKlang sound engine</summary>
		private IrrKlang.ISoundEngine _engine;
		///<summary><c>true</c> if all sounds are paused by user</summary>
		private bool _isPaused;

		internal SoundDevice() {
			Instance = this;
			_engine = new IrrKlang.ISoundEngine();
			//add custom Vortex sound factory
			_engine.AddFileFactory(new SoundFileFactory());
		}

		/// <summary>
		/// Gets the internal engine reference.
		/// </summary>
		/// <value>The internal engine reference.</value>
		internal IrrKlang.ISoundEngine Engine {
			get { return _engine; }
		}

		/// <summary>
		/// Gets the name of sound device.
		/// </summary>
		/// <value>The name of sound device.</value>
		public string Name {
			get { return _engine.Name; }
		}

		/// <summary>
		/// Gets or sets the global sound volume.
		/// </summary>
		/// <value>The sound volume in range 0..1 (0 is mute, 1 - max laud).</value>
		public float Volume {
			get { return _engine.SoundVolume; }
			set { _engine.SoundVolume = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating sound device is paused.
		/// </summary>
		/// <value><c>true</c> if this sound device is paused; otherwise, <c>false</c>.</value>
		public bool IsPaused {
			get { return _isPaused; }
			set { _isPaused = value; _engine.SetAllSoundsPaused(value); }
		}

		/// <summary>
		/// Stops all currently playing sounds.
		/// </summary>
		public void StopAll() {
			_engine.StopAllSounds();
		}
	}
}
